package component

import (
	"errors"
	"wzgames/pkg/config"
)

var ComponentNotImplemented = errors.New("Component Not Implemented")

type Component interface {
	ID() string
	Create(*ComponentConfig) (interface{}, error)
	Init(interface{}, *ComponentConfig) error
	Start(interface{}) error
	Stop(interface{}) error
	Update(interface{}, *ComponentConfig) (interface{}, error)
	Destroy(inst interface{}) error
}

type ComponentConfig struct {
	ID       string
	Name     string
	Config   config.ConfData
	Dateline int64
}

func (cc *ComponentConfig) Update(v config.ConfData) {
	cc.Config = v
}

type DefaultComponent struct{}

func (dfc *DefaultComponent) ID() string {
	return ""
}

func (dfc *DefaultComponent) Create(*ComponentConfig) (interface{}, error) {
	return nil, ComponentNotImplemented
}

func (dfc *DefaultComponent) Init(inst interface{}, c *ComponentConfig) error {
	return nil
}

func (dfc *DefaultComponent) Start(inst interface{}) error {
	return ComponentNotImplemented
}

func (dfc *DefaultComponent) Stop(inst interface{}) error {
	return nil
}

func (dfc *DefaultComponent) Update(inst interface{}, c *ComponentConfig) (interface{}, error) {
	return nil, nil
}

func (dfc *DefaultComponent) Destroy(inst interface{}) error {
	return nil
}
